package com.glink.manage.common;

import com.glink.common.exception.GeneralSimpleException;
import lombok.extern.slf4j.Slf4j;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : qiushaoshan
 * @create 2024/7/3 13:56
 */
@Slf4j
public class CheckDataUtil {

    /**
     * 校验密码规则
     * @param pwd 密码
     * @throws GeneralSimpleException 异常信息
     */
    public static void throwIfPwdNotRule(String pwd) throws GeneralSimpleException {
//        String reg = "^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$).{8,20}$";
        String reg = "^(?![0-9A-Za-z]+$)[0-9A-Za-z~!@#$%^&*()_+`\\-={}|\\[\\]\\\\:\";'<>?,./]{8,20}$";
        Pattern pattern = Pattern.compile(reg);
        Matcher matcher = pattern.matcher(pwd);
        if (!matcher.find()) {
            log.info("UserServiceImpl.throwIfMobileNotRule name-{} 密码包括数字及大小写字母以及特殊字符,长度为8-20", pwd);
            throw new GeneralSimpleException("400024");
        }
    }

    /**
     * 校验用户编号
     * @param userNumber 用户编号
     * @return 校验状态
     * @throws GeneralSimpleException 异常信息
     */
    public static boolean userNumber(String userNumber) {
        String reg = "^[_ a-zA-Z0-9]+$";
        Pattern pattern = Pattern.compile(reg);
        Matcher matcher = pattern.matcher(userNumber);
        return matcher.find();
    }
}
